package ua.org.inspace.nosqlgui;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created by: Mykhailo Matiiasevych
 * Date: 03.11.11
 * Time: 12:20
 */
public class LogStreamListener implements Runnable {

    InputStream in;
    String log;
    Level level;

    public LogStreamListener(InputStream in, String log, Level level) {
        this.in = in;
        this.log = log;
        this.level = level;
    }

    public void run() {
        try {
        InputStreamReader isr = new InputStreamReader(in);
        BufferedReader br = new BufferedReader(isr);
        String line;

        while ((line = br.readLine()) != null) {
            Logger.getLogger(log).log(level, line);
        }
        } catch (IOException ioex) {
            Logger.getLogger(log).log(level, Arrays.toString(ioex.getStackTrace()));
        }
    }
}
